package chwgigs.swing;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;



public class SwingPopupMenu extends JPopupMenu {
	

	JPopupMenu popup = null;
 
	
	public SwingPopupMenu( JPanel p) {
		  //팝업매뉴 생성
		   popup = new JPopupMenu();
		   JMenuItem m1 = new JMenuItem ("new");
		   popup.add(m1);
			p.addMouseListener( new PopupMenuListener(popup)); 

	}
	
	class PopupMenuListener extends MouseAdapter {
	
		private JPopupMenu popup;
		public PopupMenuListener(JPopupMenu popup) {
			this.popup= popup ;
		}
		public void mousePressed(MouseEvent e) {
			if (e.isPopupTrigger()) {
				showMenu(e);
			}
		}
		public void mouseReleased(MouseEvent e) {
			if (e.isPopupTrigger()) {
				showMenu(e);
			}
		}
		private void showMenu(MouseEvent e) {
			popup.show(e.getComponent(), e.getX(), e.getY());
		}

	}


}//